package com.me.model;

import cn.hutool.crypto.digest.DigestUtil;

import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

//吕旺平
public abstract class User {
	protected String id;
	protected String email;
	protected String username;
	protected String password;
	protected boolean isAdmin;
	protected boolean isConfirm;
	protected int score;
	protected Map<Integer, Item> itemMap = new HashMap<>();
	
	public User() {
		score = -1;
	}
	
	public User(String id,String email, String username, String password) {
		password = DigestUtil.md5Hex(password);
		this.id = id;
		this.email = email;
		this.username = username;
		this.password = password;
		score = -1;
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}

	public boolean comparePwd(String pwd){
		return password.equals(DigestUtil.md5Hex(pwd));
	}
	
	public void setPassword(String password) {
		password = DigestUtil.md5Hex(password);
		this.password = password;
	}
	
	public boolean isConfirm() {
		return isConfirm;
	}
	
	public boolean getIsConfirm() {
		return isConfirm;
	}
	
	public void setConfirm(boolean confirm) {
		isConfirm = confirm;
	}
	
	public boolean isAdmin() {
		return isAdmin;
	}

	public boolean getIsAdmin() {
		return isAdmin;
	}

	public void setAdmin(boolean admin) {
		isAdmin = admin;
	}
	
	public void setScore(int score) {
		this.score = score;
	}
	
	public Map<Integer, Item> getItemMap() {
		return itemMap;
	}
	
	public void setItemMap(Map<Integer, Item> itemMap) {
		this.itemMap = itemMap;
	}
	
	public abstract int getScore() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException;
	
	public abstract Collection<Item> getAllItem() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException;
}
